/////////////////////
// RPE-LTP Decoder //
/////////////////////

#include "fxp.h"
#include "defines.h"
#include "lar_logic.h"
#include "rpe_logic.h"

#ifndef RPE_LTP_RX_H
#define RPE_LTP_RX_H

// RPE decoding clause(5.3.1)
void rpe_decoding(int Mc, int16_t xmaxcr,int16_t* xMcr,int16_t* erp);
// Long term synthesis filtering(5.3.2)
void lt_synth_filter(int bcr,int Ncr,int16_t* drp,int16_t* drpp,int16_t* erp,int k);
// Computation of the decoded reflection coefficients(5.3.3)
void decode_lar(int16_t* LARcr, int16_t* rpr);
// Short term synthesis filtering clause(5.3.4)
void st_synth_filter(int16_t* drp, int16_t* sr);
// De-emphasis filtering(5.3.5)
void de_emphasis_filter(int16_t* sr,int16_t* sro);
// Upscaling of the output signal(5.3.6)
void upscaling_output(int16_t* sro, int16_t* srop);
// Truncation of the output variable(5.3.7)
void truncation_output(int16_t* srop);

// Decoder prototype
void rpeltp_decoder(
		// For each primary frame
		int16_t* LARc,
		// For each secondary frame
		int16_t* LPT_P1,
		int16_t* LPT_b1,
		int16_t* RPE_M1,
		int16_t* RPE_xmaxc1,
		int16_t* RPE_xMp1,

		int16_t* LPT_P2,
		int16_t* LPT_b2,
		int16_t* RPE_M2,
		int16_t* RPE_xmaxc2,
		int16_t* RPE_xMp2,

		int16_t* LPT_P3,
		int16_t* LPT_b3,
		int16_t* RPE_M3,
		int16_t* RPE_xmaxc3,
		int16_t* RPE_xMp3,

		int16_t* LPT_P4,
		int16_t* LPT_b4,
		int16_t* RPE_M4,
		int16_t* RPE_xmaxc4,
		int16_t* RPE_xMp4,
		// Output
		// Primary voice frame
		int16_t* p_frame
);

void unpack_decoder_homing_frame(
				// Output
				// For each primary frame
				int16_t* LARc,
				// For each secondary frame
				int16_t* LTP_P1,
				int16_t* LTP_b1,
				int16_t* RPE_M1,
				int16_t* RPE_xmaxc1,
				int16_t* RPE_xMc1,

				int16_t* LTP_P2,
				int16_t* LTP_b2,
				int16_t* RPE_M2,
				int16_t* RPE_xmaxc2,
				int16_t* RPE_xMc2,

				int16_t* LTP_P3,
				int16_t* LTP_b3,
				int16_t* RPE_M3,
				int16_t* RPE_xmaxc3,
				int16_t* RPE_xMc3,

				int16_t* LTP_P4,
				int16_t* LTP_b4,
				int16_t* RPE_M4,
				int16_t* RPE_xmaxc4,
				int16_t* RPE_xMc4,
				// Input - Packed voice frame
				uint8_t* dhf
		);

#endif
